"use client"
import FramerWrapper from "@/components/animation/FramerWrapper";
import Heading from "@/components/Heading";
import { Badge } from "@/components/ui/badge";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Mail, Phone, MapPin, Copy, Check } from "lucide-react";
import { portfolioConfig } from "@/config/portfolio.config";
import Link from "next/link";
import { useState } from "react";

const ContactPage = () => {
  const [copiedIndex, setCopiedIndex] = useState<number | null>(null);

  const handleCopy = async (text: string, index: number) => {
    try {
      await navigator.clipboard.writeText(text);
      setCopiedIndex(index);
      setTimeout(() => setCopiedIndex(null), 2000);
    } catch (err) {
      console.error('复制失败:', err);
    }
  };

  const contactInfo = [
    {
      icon: <Mail className="h-5 w-5" />,
      label: "邮箱地址",
      value: portfolioConfig.email,
      href: `mailto:${portfolioConfig.email}`,
      copyable: true
    },
    {
      icon: <MapPin className="h-5 w-5" />,
      label: "所在地区",
      value: portfolioConfig.location,
      href: null,
      copyable: false
    }
  ];

  return (
    // CONTACT PAGE
    <div className="h-full w-full relative flex flex-col items-start gap-5 overflow-hidden">
      <Badge variant="secondary" className="gap-1.5 py-1 ">
        <Phone className="h-4 w-4" />
        联系我
      </Badge>
      <div className="flex flex-col gap-3 w-full">
        <Heading>联系方式</Heading>
        
        <div className="w-full max-w-2xl">
          <FramerWrapper y={0} scale={0.8}>
            <Card>
              <CardHeader>
                <CardTitle className="icon_underline">联系信息</CardTitle>
                <CardDescription>
                  欢迎通过以下方式与我联系，我会尽快回复您的消息。
                </CardDescription>
              </CardHeader>
              <CardContent className="space-y-4">
                {contactInfo.map((info, index) => (
                  <div key={index} className="flex items-center justify-between p-4 border rounded-lg hover:bg-gray-50 transition-colors">
                    <div className="flex items-center gap-3">
                      <div className="text-primary">{info.icon}</div>
                      <div>
                        <p className="font-medium text-sm text-gray-600">{info.label}</p>
                        {info.href ? (
                          <Link 
                            href={info.href} 
                            className="text-base font-medium text-gray-900 hover:text-primary transition-colors"
                          >
                            {info.value}
                          </Link>
                        ) : (
                          <p className="text-base font-medium text-gray-900">{info.value}</p>
                        )}
                      </div>
                    </div>
                    {info.copyable && (
                      <button 
                        onClick={() => handleCopy(info.value, index)}
                        className="p-2 text-gray-400 hover:text-primary transition-colors"
                        title="复制邮箱地址"
                      >
                        {copiedIndex === index ? (
                          <Check className="h-4 w-4 text-green-500" />
                        ) : (
                          <Copy className="h-4 w-4" />
                        )}
                      </button>
                    )}
                  </div>
                ))}
              </CardContent>
            </Card>
          </FramerWrapper>
        </div>
        
        <div className="mt-6">
          <FramerWrapper y={20} delay={0.2}>
            <p className="text-sm text-gray-600 max-w-2xl">
              💡 您也可以通过页面底部的社交媒体链接关注我的技术动态，或访问我的技术博客了解更多内容。
            </p>
          </FramerWrapper>
        </div>
      </div>
    </div>
  );
};

export default ContactPage;
